package com.clg.user;

import com.clg.common.model.User;
import com.clg.common.tools.MD5Tools;
import com.clg.common.tools.RetRes;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;

import javax.security.auth.login.LoginException;

/**
 * Created by usercai on 2016/9/28.
 */
@Before(Tx.class)
public class LoginService {

    public RetRes loginAuth(String loginName, String password){
        User user = User.dao.findUserByLoginName(loginName);
        if(user==null){
            return RetRes.create().setMessage("用户名不存在!");
        }
        if(!MD5Tools.getPassMd5(password,user.getUserPassSalt()).equals(user.getUserPass())){
            return RetRes.create().setMessage("密码不正确");
        }
        return RetRes.create(true).put("user",user);
    }
}
